# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/2 下午5:37
 @Author  : tgy
 
"""
import json
from pprint import pprint

from json_utils import JsonUtils


class Person:
    ...
    def __init__(self, d):
        self.__dict__ = d


class Dog:
    ...
    def __init__(self,name, age):
        self.name = name
        self.age = age

#
def test():
    ...
    """
    None => null,
    False => false
    True => true
    """
    d = {'name': None, 'flag': False, 'sex': True}
    d_str = json.dumps(d,indent=4)
    print(d_str)

    pprint(d_str)
    # json转对象
    per = json.loads(d_str, object_hook=Person)

    # print(per.__dict__)
    print(per.flag)
    print(vars(per))

def test01():
    ...
    dog = Dog(name='tony', age=21)

    dog_str = json.dumps(JsonUtils.serialize_instance(dog), indent=4)
    print(dog_str)

    load_dog = JsonUtils.unserialize_instance(json.loads(dog_str), Dog)
    print(load_dog)


if __name__ == '__main__':
    ...
    test01()
